#!/bin/bash
echo "####if else"
echo "input two number a and b"
read a
read b

if (($a >= $b));then
	echo "a bigger then b or a equals b"
fi

if (($a > $b));then
	echo "a bigger then b"
else
	echo "b bigger then a or b eqauls a"
fi

echo "input age"

read age
if (($age>=0 && $age<=125));then
	if (($age<20));then
		echo "少年"
	elif (($age<30));then
		echo "青年"
	elif (($age<50));then
		echo "中年"
	elif (($age<100));then
		echo "老年"
	else 
		echo "wtf"
	fi
else
	echo "age is illegal!"
fi


echo "####case in"
echo "input a character"

read char

case $char in 
	[a-z])
		echo "is lower word"
		;;
	[A-Z])
		echo "is higher word"
		;;
	[0-9])
		echo "is number"
		;;
	[.,!?])
		echo "is punctuation"
		;;
	*)
		echo "other character"
		;;
esac
		
echo "#### while"
echo "input start num"

read startnum

echo "input end num"

read endnum

result=0
while ((startnum<=endnum))
do
	((result+=startnum))
	((startnum++))
done

echo "the sum from $startnum to $endnum is $result"

echo "##### for"

for n in "test" 1 2 4 "summer"
do
	echo "$n"
done

for n in {a..Z}
do
	echo "$n"
done

for n in $(ls -a)
do
	echo "$n"
done

for n in *.sh
do
	echo "$n"
done

function each(){
	
	for n in $@
	do
		echo "$n"
	done
}

each "ok" "bash" "shell"

function each2(){
	for n
	do
		echo "$n"
	done
}

each2 "no" "yet" "but"

echo "#### select in"
select n in "MAC OS" "Linux" "UNIX" "WINDOWS"
do
	echo "$n"
done

echo "#### break and continue"

sum=0
while read n; do
	if ((n<0)); then
		echo "n lower than 0;break!"
		break
	elif ((n==10)); then
		echo "n is 10;plus 100"
		((sum+=100))
	else
		echo "other continue"
		continue
	fi
done

echo "sum is $sum"
	
